<template>
  <el-dialog :visible="visible">
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
      <el-form-item label="新增车型" />
      <el-form-item label="车辆类型" prop="name">
        <el-input v-model="form.name" placeholder="请输入车辆类型" />
      </el-form-item>
      <el-form-item label="应载重量" prop="allowableLoad">
        <el-input v-model="form.allowableLoad" placeholder="请输入应载重量">
          <template slot="append">吨</template>
        </el-input>
      </el-form-item>
      <el-form-item label="应载体积" prop="allowableVolume">
        <el-input v-model="form.allowableVolume" placeholder="请输入应载体积">
          <template slot="append">立方</template>
        </el-input>
      </el-form-item>
      <el-form-item label="长" prop="measureLong">
        <el-input v-model="form.measureLong">
          <template slot="append">米</template>
        </el-input>
      </el-form-item>
      <el-form-item label="宽" prop="measureWidth">
        <el-input v-model="form.measureWidth">
          <template slot="append">米</template>
        </el-input>
      </el-form-item>
      <el-form-item label="高" prop="measureHigh">
        <el-input v-model="form.measureHigh">
          <template slot="append">米</template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确定</el-button>
        <el-button @click="defaultArr">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import { addition, layoutAxios } from '@/api/organic'
export default {
  props: {
    visible: {
      type: Boolean,
      default: true
    }
  },

  data() {
    return {
      form: {
        name: '', /* 车辆类型 */
        allowableLoad: -1 && '', /* 准载重量 */
        allowableVolume: -1 && '', /* 准载体积 */
        measureHigh: -1 && '', /* 高 */
        measureLong: -1 && '', /* 长 */
        measureWidth: -1 && '' /* 宽 */
      },
      rules: {
        name: [{ required: true, message: '车辆类型不能为空', trigger: 'blur' }],
        allowableLoad: [{ required: true, message: '应载重量不能为空', trigger: 'blur' }],
        allowableVolume: [{ required: true, message: '准载体积不能为空', trigger: 'blur' }],
        measureHigh: [{ required: true, message: '高度不能为空', trigger: 'blur' }],
        measureLong: [{ required: true, message: '长度不能为空', trigger: 'blur' }],
        measureWidth: [{ required: true, message: '宽不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.layoutForm()
  },
  methods: {
    async  onSubmit() {
      this.$refs.form.validate(async isok => {
        if (isok) {
          await addition(this.form)
          this.$message.success('新增成功')
          this.layoutForm()
          this.defaultArr()
        }
      })
    },
    // 获取页面渲染数据详情
    async  layoutForm() {
      const res = await layoutAxios()
      // console.log(res)
      this.tableData = res.data.data
    },
    // 控制模态框隐藏
    defaultArr() {
      this.$emit('visible', false)
    }
  }
}
</script>
